package edu.zhku.ttms.view.panel.component;

import edu.zhku.ttms.utils.SystemConst;
import edu.zhku.ttms.view.panel.content.AbstractManagementPanel;

import javax.swing.*;

/**
 * @author Feng
 * @since 2021/4/23 17:57
 */
public class QueryPanel extends JPanel {

    public QueryPanel(AbstractManagementPanel owner) {
        this(owner, 100, 40);
    }

    public QueryPanel(AbstractManagementPanel owner, int x, int y) {

        this.setLayout(null);
        this.setBounds(x, y, 430, 25);

        this.setBackground(SystemConst.BACKGROUND_COLOR);
        this.setOpaque(true);

        JTextField queryTextField = new JTextField();
        queryTextField.setBounds(0, 0, 200, 25);
        this.add(queryTextField);

        JButton queryButton = new JButton("查询");
        queryButton.setBounds(250, 0, 70, 25);
        queryButton.addActionListener(e -> {
            String queryStr = queryTextField.getText();
            owner.loadData(queryStr, 1);
        });
        this.add(queryButton);

        JButton resetButton = new JButton("重置");
        resetButton.setBounds(350, 0, 70, 25);
        resetButton.addActionListener(e -> {
            queryTextField.setText("");
            owner.initData();
        });
        this.add(resetButton);
    }
}